<template>
  <el-container class="main_con" style="padding-bottom: 0px">
    <ufrom @submit="saveData" ref="ufrom">
      <el-form size="medium" label-width="100px" ref="itemForm" :model="config.configuration">
        <div class="setting_body_item">
          <div class="header">下单后获取抽奖设置</div>
          <div class="conetnt edit_con">
            <div class="edit_content">
              <el-form-item label-width="130px">
                <span slot="label">抽奖设置</span>
                <el-radio-group v-model="config.configuration.lottery_open">
                  <el-radio :label="1">开启</el-radio>
                  <el-radio :label="0">关闭</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item label-width="130px">
                <span slot="label">抽奖样式</span>
                <el-radio-group v-model="config.configuration.lottery_style" :disabled="config.configuration.lottery_open == 0 ? true : false">
                  <el-radio :label="item.id" v-for="(item, i) in alist" :key="i">{{ item.value }}</el-radio>
                  <!--   <el-radio :label="1">九宫格</el-radio>
                    <el-radio :label="2">刮刮乐</el-radio> -->
                </el-radio-group>
              </el-form-item>

              <el-form-item label="获取抽奖次数方式" label-width="130px">
                <el-radio-group v-model="config.configuration.lottery_type" :disabled="config.configuration.lottery_open == 0 ? true : false">
                  <el-radio :label="1">订单</el-radio>
                  <el-radio :label="2">金额</el-radio>
                </el-radio-group>
              </el-form-item>

              <div style="display: flex" v-if="config.configuration.lottery_type == 1">
                <el-form-item prop="get_number" label-width="130px">
                  <span>每个订单赠送</span>
                  <el-input style="width: 160px;margin: 0 20px;" size="small" v-model="config.configuration.lottery_number" :min="1" :disabled="config.configuration.lottery_open == 0 ? true : false">
                    <template slot="append">
                      次
                    </template>
                  </el-input>
                  <span>抽奖机会</span>
                </el-form-item>
              </div>
              <div style="display: flex" v-else>
                <el-form-item label-width="130px">
                  <span>满</span>
                  <el-input style="width: 160px;margin: 0 20px;" size="small" v-model="config.configuration.lottery_money" :min="1" :disabled="config.configuration.lottery_open == 0 ? true : false">
                    <template slot="append">
                      元
                    </template>
                  </el-input>
                  <span>赠送</span>
                </el-form-item>
                <el-form-item label-width="0">
                  <el-input style="width: 160px;margin: 0 20px;" size="small" v-model="config.configuration.lottery_number" :min="1" :disabled="config.configuration.lottery_open == 0 ? true : false">
                    <template slot="append">
                      次
                    </template>
                  </el-input>
                  <span>抽奖机会</span>
                </el-form-item>
              </div>
              <el-form-item label-width="130px">
                <el-checkbox v-model="config.configuration.superposition" :disabled="config.configuration.lottery_open == 0 ? true : false">赠送次数可以叠加</el-checkbox>
              </el-form-item>
              <el-form-item label="抽奖赠送次数限制" prop="get_limit" label-width="130px">
                <span>每个账号每天最多赠送</span>
                <el-input style="width: 160px;margin: 0 20px;" size="small" v-model="config.configuration.lottery_limit" :disabled="config.configuration.lottery_open == 0 ? true : false">
                  <template slot="append">
                    次
                  </template>
                </el-input>
                <span>抽奖机会</span>
              </el-form-item>
            </div>
          </div>
        </div>
      </el-form>
    </ufrom>
  </el-container>
</template>

<script>
import {getLotteryConfig, editLotteryConfig, postLotteryConfig} from '@/api/mall/setting';
import {jur_addons_item, jur_addons} from '@/utils/jurisdiction';
export default {
  data() {
    return {
      config: {},
      alist: []
    };
  },
  created() {
    this.getData();
  },
  methods: {
    saveData() {
      // 抽奖 提交 修改
      let data = {
        configuration: {
          ...this.config.configuration
        }
      };
      if (this.config.update_time) {
        data.update_time = this.config.update_time;
        editLotteryConfig(data)
          .then(res => {
            this.$refs.ufrom.init();
            this.getData();
          })
          .catch(e => {
            this.$refs.ufrom.init();
          });
      } else {
        postLotteryConfig(data)
          .then(res => {
            this.$refs.ufrom.init();
            this.getData();
          })
          .catch(e => {
            this.$refs.ufrom.init();
          });
      }
    },
    getData() {
      getLotteryConfig().then(res => {
        this.config = res.msg;
        this.alist = [];
        jur_addons([17, 18]).then(res => {
          if (res[17]) {
            this.alist.push({id: 1, value: '九宫格'});
          }

          if (res[18]) {
            if (!res[17]) {
              this.config.configuration.lottery_style = 2;
            }
            this.alist.push({id: 2, value: '刮刮乐'});
          }
        });
      });
    }
  }
};
</script>

<style lang="scss" scoped>


</style>
